<template>

</template>
<style>

</style>
<script>
  var qs = require('qs');
  import axios from 'axios'
  export default{
    mounted(){
      var openid=this.GetQueryString('openid');
      console.log(openid);
      this.axios.post("/auth",qs.stringify({ 'openid': openid })).then((response) => {
        if(response.data.code===200){
          localStorage.token=response.data.object;
          axios.defaults.headers.common['Authorization'] = "Bearer "+localStorage.token;
          console.log(localStorage.token);
          console.log(response.data);
          console.log(this.GetQueryString("state"));
          this.$router.push({ path: this.GetQueryString("state")});
        }
      })
    },
    methods:{
      GetQueryString:function(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
         var r = window.location.search.substr(1).match(reg);
         if(r!=null)return  unescape(r[2]); return null;
      }
    }
  }

</script>
